﻿

using System.Windows;
using System.Collections.ObjectModel;
using DeepEarth.Map.Core;
using System;
using System.Windows.Media;
using DeepEarth.Core;
namespace DeepEarth.Toolkit.Geometry
{
    public class LineString : PathBase, ISelfPositioning, IMultiLocation
    {
        protected override void Refresh()
        {
            PathGeometry pg = new PathGeometry();
            var figures = ShapeHelper.CreateSafeFigures(Locations, LocationToPoint, false, MaxBound);

            foreach (var figure in figures)
            {
                pg.Figures.Add(figure);            
            }
            this.Data = pg;
        }

        double? originalStrokeThickness = null;

        public override void ApplyScale(double scale, double appliedScaleTransform)
        {
            if (originalStrokeThickness == null)
            {
                originalStrokeThickness = this.StrokeThickness;
            }

            // If stroke thickness is too small, the line will disappear even if we're enlarging.
            var provisional = originalStrokeThickness.Value * appliedScaleTransform;

            this.StrokeThickness = Math.Max(provisional, 0.15);
        }

        #region IMultiLocation
    
        System.Collections.Generic.IEnumerable<Location> IMultiLocation.Locations
        {
            get { return Locations; }
        }

        public Location Position
        {
            get
            {
                return BoundingRectangle.Center;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public LocationRectangle BoundingBox
        {
            get { return BoundingRectangle; }
        }

        #endregion
    }
}
